//
//  GrapghSelecetedState.m
//  MusicAnalyzer
//
//  Created by jiro on 12/04/04.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "GraphSelecetedState.h"

#import "../AppController.h"

static GraphSelecetedState* instance = nil;

@implementation GraphSelecetedState

+ (id) sharedState
{
	if ( instance == nil )
	{	//	implicit call "+(id)allocWithZone:(NSZone *)zone"
		[ [self alloc ] init ];
	}
	return instance;
}


+ (id)allocWithZone:(NSZone *)zone
{
    @synchronized(self)
	{
        if ( instance == nil)
		{
            instance = [super allocWithZone:zone];
			[ instance setStateType: StateType_GraphSelectedState ];
            return instance;
        }
    }
    return nil;
}

- (id)copyWithZone:(NSZone *)zone
{
    return self;
}
 
- (id)retain
{
    return self;
}
 
- (NSUInteger)retainCount
{
    return UINT_MAX;
}
 
- (void)release
{
}
 
- (id)autorelease
{
    return self;
}

- (Command*) commandToKeyEvent: (AppKeyEvent*) e returnTransitInfo: ( StateTransitionInfo* ) info
{
	@throw( [ NotImplementedException exception ] );
}

- (Command*) commandToMouseEvent: (AppMouseEvent*) e returnTransitInfo: ( StateTransitionInfo* ) info
{
	id eventInstance = [ e eventInstance ];
	if ( eventInstance == [ [ SM appController ] musicSheetView ] )
	{
		[ info setPopCount: 2 ];
		[ info addPushState: [ GraphViewActiveState sharedState ] ];
		[ info addPushState: [ GraphDeselectedState sharedState ] ];
		return [ [ ActivateGraphViewCommand alloc ] init ]; 
	}
	else if ( eventInstance == [ [ SM appController ] graphView ] )
	{
		//	select or deselect
	}
	else if ( eventInstance == [ [ SM appController ] chordTableView ] )
	{
		[ info setPopCount: 2 ];
		[ info addPushState: [ ChordTableViewActiveState sharedState ] ];
		[ info addPushState: [ ChordTableViewChordDeselectedState sharedState ] ];
		return [ [ ActivateChordListCommand alloc ] init ];
	}
	return nil;
}

- (Command*) commandToMidiEvent: (AppMidiEvent*) e returnTransitInfo: ( StateTransitionInfo* ) info
{
	@throw( [ NotImplementedException exception ] );
}

@end
